<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box">
        <input type="password" id="input">
        <button id="button">显示</button>
    </div>
    <script>
        //1.获取元素
        var password = document.getElementById('input')
        var button = document.getElementById('button')
        //绑定事件
        var flag = 0
        button.onclick = function () {
            if (flag == 0) {
                password.type = 'text'
                button.innerHTML = "隐藏"
                flag = 1
            } else {
                password.type = 'password'
                button.innerHTML = "显示"
                flag = 0
            }
        }
    </script>
</body>

</html>